//
//  HWBookTicketViewController.m
//  嗨文
//
//  Created by 响当当 on 2019/2/22.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWBookTicketViewController.h"
#import "HWBookTicketView.h"

@interface HWBookTicketViewController ()
@property (nonatomic, strong)HWBookTicketView *bookTicketView;
@end

@implementation HWBookTicketViewController


- (HWBookTicketView *)bookTicketView
{
    if (!_bookTicketView)
    {
        _bookTicketView = [[HWBookTicketView alloc]initWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT-NAVIBAR_HEIGHT)];
    }
    return _bookTicketView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"书券"];
    [self setDefaultNav];
    
    [self.view addSubview:self.bookTicketView];

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self buryPoint];
    [self getInfor];

}

#pragma mark - 获取书券信息
- (void)getInfor
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token                               };
    
    WeakSelf(self)
    [MyInfoManager setBookToken:prarmers sucess:^(id  _Nonnull acceptData) {
        [weakSelf.bookTicketView getBookToken:acceptData];
    } fail:^(NSError * _Nullable error) {
        DISMISS_SVP(1.0f);
        [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
        DISMISS_SVP(1.0f);
    }];
}

- (void)buryPoint
{
    NSString *lastStayTime = [kUserDefaults objectForKey:@"time"];
    NSString *nowStayTime = [NSString stringWithFormat:@"%ld",[[HWUtilties getNowTimeTimestamp3] integerValue] - lastStayTime.integerValue];
    
    [HWUtilties buryPointWithStayTime:nowStayTime
                            timestamp:[HWUtilties getNowTimeTimestamp3]
                             memberId:current_User.userID
                              fromUrl:nil
                                toUrl:@"/bookToken"
                               fromId:nil
                                 toId:@"d4f56a2304d574da"];
}

@end
